commonlibsse_ng\re\c/
Calendar.rs1mod day;
2mod month;
3mod time;
4mod year;
5
6use core::ffi::c_char;
7
8pub use self::day::{GameDay, Week};
9pub use self::month::{MonthInGame, MonthIndex};
10pub use self::time::{GameDateTime, Hour};
11pub use self::year::Year;
12use crate::re::TESGlobal::TESGlobal;
13
14#[repr(C)]
16#[derive(Debug)]
17pub struct Calendar {
18 pad01: u8, pad02: u16, pad04: u32, game_year: *mut TESGlobal, game_month: *mut TESGlobal, game_day: *mut TESGlobal, game_hour: *mut TESGlobal, game_days_passed: *mut TESGlobal, time_scale: *mut TESGlobal, midnights_passed: u32, raw_days_passed: f32, }
30
31const _: () = {
32 assert!(core::mem::size_of::<Calendar>() == 0x40);
33};
34
35impl Calendar {
36 #[commonlibsse_ng_derive_internal::relocate(
38 cast_as = "*mut *mut Calendar",
39 default = "None",
40 deref_once,
41 id(se = 514287, ae = 400447)
42 )]
43 pub fn get_singleton() -> Option<&'static Calendar> {
44 |deref_type: DerefType| unsafe { deref_type.as_ref() }
45 }
46
47 #[inline]
49 pub fn get_current_game_time(&self) -> Option<Hour> {
50 debug_assert!(crate::rex::win32::is_accessible_struct(self.game_days_passed));
51 unsafe { self.game_days_passed.as_ref().map(|g| Hour::new(g.value)) }
52 }
53
54 #[inline]
56 pub fn get_day(&self) -> Option<GameDay> {
57 debug_assert!(crate::rex::win32::is_accessible_struct(self.game_day));
58 unsafe { self.game_day.as_ref().map(|g| GameDay::new(g.value)) }
59 }
60
61 #[inline]
63 pub fn get_day_name(&self) -> Option<&'static str> {
64 self.get_day_of_week().map(|day_of_week| day_of_week.as_str())
65 }
66
67 #[inline]
69 pub fn get_day_of_week(&self) -> Option<Week> {
70 self.get_days_passed().and_then(|day| day.to_week())
71 }
72
73 #[inline]
75 pub fn get_days_passed(&self) -> Option<GameDay> {
76 unsafe { self.game_days_passed.as_ref().map(|g| GameDay::new(g.value)) }
77 }
78
79 #[commonlibsse_ng_derive_internal::relocate_fn(se_id = 35413, ae_id = 36311)]
81 pub fn get_time_date_string(dest: *mut c_char, max: u32, show_year: bool) {}
82
83 #[inline]
85 pub fn get_hour(&self) -> Option<Hour> {
86 unsafe { self.game_hour.as_ref().map(|g| Hour::new(g.value)) }
87 }
88
89 #[inline]
91 pub fn get_hours_passed(&self) -> Option<f32> {
92 Some(self.get_days_passed()?.0 * 24.0)
93 }
94
95 #[commonlibsse_ng_derive_internal::relocate_fn(se_id = 241610, ae_id = 195681)]
97 pub fn get_hours_per_day() -> f32 {}
98
99 #[inline]
101 pub fn get_minutes(&self) -> Option<u32> {
102 Some(self.get_hour()?.to_minutes())
103 }
104
105 #[inline]
107 pub fn get_month(&self) -> Option<MonthIndex> {
108 unsafe { self.game_month.as_ref().map(|g| MonthIndex::new(g.value)) }
109 }
110
111 #[inline]
113 pub fn get_month_name(&self) -> Option<&'static str> {
114 self.get_month()?.to_enum().map(|month| month.as_str())
115 }
116
117 #[inline]
119 pub fn get_ordinal_suffix(&self) -> Option<&'static str> {
120 Some(self.get_day()?.ordinal_suffix())
121 }
122
123 pub fn get_time(&self) -> Option<GameDateTime> {
125 let year = self.get_year()?;
126 let month = self.get_month()?;
127 let day = self.get_day()?;
128 let hour = self.get_hour()?;
129 GameDateTime::new(year, month, day, hour)
130 }
131
132 #[inline]
134 pub fn get_timescale(&self) -> f32 {
135 unsafe { self.time_scale.as_ref().map_or(1.0, |g| g.value) }
136 }
137
138 #[inline]
140 pub fn get_year(&self) -> Option<Year> {
141 unsafe { self.game_year.as_ref().map(|g| Year::new(g.value)) }
142 }
143}